#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @Time   :2021/12/17
# @Author :songtx
# @File   :infuse_liquid.py


import can
from i2c import i2c
from dox_enquiry import dox_command

bus = can.Bus(interface='socketcan', channel='can0', receive_own_messages=eval('False'))
m = 1


# doxx dox_12 HC补液泵,dox_13 KCL补液泵,dox_14 pH4补液泵,dox_15 pH6补液泵
# di_07 HCL清洗液补液按钮   di_08 KCL保护液补液按钮  di_12 pH4补液按钮   di_13 pH6补液按钮
def infuse_liquid(liquid_class):  # liquid_class｜液体种类
    array2 = i2c()                                # 读当前液位
    dict1 = {'12': 0, '13': 1, '14': 2, '15': 4}  # 泵对应的液位 liquid_class 转 row
    global m
    if m == 1:                                               # 第一步
        if array2[dict1[str(liquid_class)], 1] == 0.0:       # 高液位为False
            print('++++++')
            doxx = dox_command([liquid_class])  # 液体类型DO 12｜HCL 13｜KCL 14｜pH4 15｜pH6
            msg = can.Message(arbitration_id=0x0101, data=doxx, is_extended_id=False)
            bus.send(msg, timeout=1)
        m += 1
        return
    if m == 2:                                               # 第二步
        print(liquid_class, '正在加药+++++++++')
        if array2[dict1[str(liquid_class)], 1] == 1.0:       # 高液位为True
            print('--------')
            doxx = dox_command([])
            msg = can.Message(arbitration_id=0x0101, data=doxx, is_extended_id=False)
            bus.send(msg, timeout=1)
            m += 1
        return
    if m == 3:
        edge[6] = 0  # 完成加药顺控，复位所有加药上升沿，首个加药指令有效
